package base.jdk8_demo.lambda.demo04;

import org.junit.Test;

/**
 * 对字符串封装的操作
 */
public class TestStringOperation {

    // 对str进行处理，返回一个新字符串
    interface StrOperationInterface {
        String operate(String str);
    }

    // 将str 和 operation 同时获取，并通过operation提供的operate方法对str进行处理
    static class StrOperationService {
        public static String getStr(String str, StrOperationInterface operation){
           return operation.operate(str);
        }
    }

    @Test
    public void testToUppercase() {
        String s = StrOperationService.getStr("Just Do It Now", str -> {return str.toUpperCase();});
        System.out.println(s);
    }
    @Test
    public void testTrimString(){
        String s = StrOperationService.getStr("\t\t\t 为中华崛起而读书  ", str -> str.trim());
        System.out.println(s);
    }
    @Test
    public void testSubString(){
        String s = StrOperationService.getStr("为中华崛起而读书", str -> str.substring(2, 3));
        System.out.println(s);
    }

}
